package com.ccx.demo.open.common.controller;

import com.ccx.demo.enums.RegisterSource;
import com.ccx.demo.enums.TokenClient;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.google.common.collect.Maps;
import com.support.annotations.AppSwaggerGroup;
import com.support.annotations.VueSwaggerGroup;
import com.support.annotations.WechatSwaggerGroup;
import com.support.mvc.entity.base.Result;
import com.support.mvc.enums.AppCode;
import com.utils.enums.Code;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 开发环境支撑
 *
 * @author 谢长春 on 2017/11/13.
 */
@Api(tags = "开发环境支撑")
@ApiSort(0)
@RequestMapping("/open/dev")
@Controller
@Slf4j
@RequiredArgsConstructor
@ConditionalOnExpression("!'prod'.equals('${spring.app.env}')") // 生产环境不初始化这个 controller
public class OpenDevController {
    @AppSwaggerGroup
    @VueSwaggerGroup
    @WechatSwaggerGroup
    @GetMapping("/enums")
    @ApiOperationSupport(order = 1, author = "谢长春")
    @ApiOperation(value = "查看应用所有枚举值说明", tags = {""}, notes = "")
    @ResponseBody
    public Result<Map<String, Map<String, String>>> enums() {
        return new Result<Map<String, Map<String, String>>>().execute(result -> {
//            final HashBasedTable<String, String, String> table = HashBasedTable.create();
//            for (TokenClient ele : TokenClient.values()) {
//                table.put(TokenClient.class.getSimpleName(), ele.name(), ele.comment);
//            }
            final Map<String, Map<String, String>> table = Maps.newHashMap();
            {
                table.put(TokenClient.class.getSimpleName(), Maps.newLinkedHashMap());
                for (TokenClient ele : TokenClient.values()) {
                    table.get(TokenClient.class.getSimpleName()).put(ele.name(), ele.comment);
                }
            }
            {
                table.put(Code.class.getSimpleName(), Maps.newLinkedHashMap());
                for (Code ele : Code.values()) {
                    table.get(Code.class.getSimpleName()).put(ele.name(), ele.comment);
                }
                for (AppCode ele : AppCode.values()) {
                    table.get(Code.class.getSimpleName()).put(ele.name(), ele.comment);
                }
            }
            {
                table.put(RegisterSource.class.getSimpleName(), Maps.newLinkedHashMap());
                for (RegisterSource ele : RegisterSource.values()) {
                    table.get(RegisterSource.class.getSimpleName()).put(ele.name(), ele.comment);
                }
            }
            result.setSuccess(table);
        });
    }

}
